AddCSLuaFile()

DEFINE_BASECLASS( "class_default" )

local PLAYER = {}

PLAYER.DisplayName			= "Shieldbearer"

PLAYER.WalkSpeed = 155
PLAYER.MaxHealth			= 325
PLAYER.StartHealth			= 325

PLAYER.AttackSpeed = 1.175
PLAYER.WeaponDamageMin = 5
PLAYER.WeaponDamageMax = 12

PLAYER.MainhandModel = "models/devin/rpgdm_weapons/basic/broadsword.mdl"
PLAYER.OffhandModel = "models/devin/rpgdm_weapons/basic/blueshield.mdl"
PLAYER.MainHand = nil
PLAYER.OffHand = nil

PLAYER.ResourceAmount = 1
PLAYER.ResourceMax = 1
PLAYER.RegenTime = 0
PLAYER.RegenAmount = 0
PLAYER.ResourceColor = Color(15, 15, 45, 255)


PLAYER.Spells = {
	51312,
	2142,
	70011,
	7332,
	40,
	11003,
	11013
}

function PLAYER:SetupDataTables()

	BaseClass.SetupDataTables( self )

end


function PLAYER:SetupResources()
	print("SETTING UP RESOURCES")
	self.Player.Resource = self.ResourceAmount
	self.Player.ResourceMax = self.ResourceMax
	self.Player.NextResource = CurTime() + self.RegenTime
	self.Player.ResourceTimer = self.RegenTime
	self.Player.ResourceRegen = false
	self.Player.ResourceRegenAmount = self.RegenAmount
	self.Player.ResourceColor = self.ResourceColor
	net.Start("ReceivePlayerResources")
	net.WriteTable({self.Player.Resource, self.Player.ResourceMax, self.Player.ResourceColor, self.Player})
	net.Broadcast()
end

function PLAYER:Spawn()
	self.Player.Block = 0.5
	self.Player.Dodge = 0.5
	self.Player.Parry = 0.5
	local col = team.GetColor(self.Player:Team())
	self.Player:SetPlayerColor( Vector(	col.r/255, col.g/255, col.b/255 ) )
	self.Player:SetWeaponColor( Vector( col.r/255, col.g/255, col.b/255 ) )
	print("You have spawned as a warrior!")
	timer.Destroy("SpeedModCharge")
	self.Player:SetWalkSpeed(self.WalkSpeed)
	self:Loadout()
	self:SetupGear()
	self:SetupSpells()
	self:SetupResources()
	net.Start("SendSelfMaxHealth")
	net.WriteFloat(self.MaxHealth)
	net.Send(self.Player)
end

function PLAYER:SetupGear()
	SetEquipped(self.Player, self.Player.tempEquippedItems)
end

function PLAYER:SetupSpells()
	if(!self.Player.tempSpells)then
		SetSpells(self.Player, self.Spells)
		timer.Simple(0.1, function()
			net.Start("SendPlayerSpells")
			net.WriteTable(self.Spells)
			net.Send(self.Player)
		end)
	end
end

function PLAYER:Loadout()
	self.MainHand = ents.Create("prop_dynamic")
	self.MainHand:SetModel(self.MainhandModel)
	self.MainHand:PhysicsInit(SOLID_VPHYSICS)
	self.MainHand:SetMoveType(MOVETYPE_NONE)
	self.MainHand:SetSolid( SOLID_VPHYSICS )
	self.MainHand:SetParent(self.Player)
	self.MainHand:AddEffects( EF_BONEMERGE )
	self.Player:SetNWEntity("MainWep", self.MainHand)
	self.OffHand = ents.Create("prop_dynamic")
	self.OffHand:SetModel(self.OffhandModel)
	self.OffHand:PhysicsInit(SOLID_VPHYSICS)
	self.OffHand:SetMoveType(MOVETYPE_NONE)
	self.OffHand:SetSolid( SOLID_VPHYSICS )
	self.OffHand:SetParent(self.Player)
	self.OffHand:AddEffects( EF_BONEMERGE )
	self.Player:SetNWEntity("OffWep", self.OffHand)
	self.Player:Give( "weapon_all" )
	local weapon = self.Player:GetWeapon("weapon_all")
		
	weapon.AttackSpeed = self.AttackSpeed
	weapon.MinWeaponDamage = self.WeaponDamageMin
	weapon.MaxWeaponDamage = self.WeaponDamageMax
	weapon.WeaponStance = "shield"
	self.Player:SetNWString("HoldType", "knife")
end

function PLAYER:OnHit(typehit)
	target = self.Player:GetNetworkedEntity("Target")
	if(typehit == 5)then
		target:EmitSound("devin/blackbetty/weapons/2HMaceHitPlateCrit.wav", 150, 100+math.random(-10,-30))
		target:SetVelocity((((self.Player:GetPos()) - target:GetPos())*-9))
		ParticleEffect( "pummel_hit", target:GetPos() + Vector(0, 0, 46) + (target:GetAngles():Forward()*7), Angle(0,0,0), target )
	else
		ParticleEffect( "player_blood", target:GetPos() + Vector(0, 0, 46) + (target:GetAngles():Forward()*6), Angle(0,0,0), target )
		self.Player:EmitSound("devin/blackbetty/weapons/heroic_strike/hit_"..math.random(1,3)..".wav", 100, 100+math.random(-10,10))
		if(timer.Exists("rend_on_"..target:EntIndex()..""))then
			timer.Destroy("rend_on_"..target:EntIndex().."")
		end
		timer.Create("rend_on_"..target:EntIndex().."", 1, 10, function() 
			if(!target or !target:IsValid() or target:Health() <= 0) then 
				timer.Destroy("rend_on_"..target:EntIndex().."")  
			else
				local dmginfo_im = DamageInfo()
					dmginfo_im:SetDamage( 3 ) 
					dmginfo_im:SetDamageType( DMG_ENERGYBEAM )
					dmginfo_im:SetAttacker( self.Player ) 
					dmginfo_im:SetDamageForce( Vector( 0, 0, 1000 ) ) 
				target:TakeDamageInfo( dmginfo_im )
				
				ParticleEffect( "player_blood", target:GetPos() + Vector(0, 0, 64) + (target:GetAngles():Forward()*24), Angle(0,0,0), target )
			end
		end)
	end
end
	
player_manager.RegisterClass( "class_shieldbearer", PLAYER, "class_default" )